package org.springblade.modules.admin.controller.suger;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.AllArgsConstructor;
import org.springblade.core.tenant.annotation.TenantIgnore;
import org.springblade.core.tool.api.R;
import org.springblade.modules.admin.dto.AnalysisStatisticalDTO;
import org.springblade.modules.admin.dto.sugar.mal.SugarMalSearchDTO;
import org.springblade.modules.admin.service.IMaintainMalfunctionWorkService;
import org.springblade.modules.admin.service.IMaintainPlanContentExtService;
import org.springblade.modules.admin.service.IMaintainPlanContentService;
import org.springblade.modules.admin.vo.sugar.ChartVO;
import org.springblade.modules.admin.vo.sugar.MalPlanOverviewVO;
import org.springblade.modules.admin.vo.sugar.MalfunctionScreenVO;
import org.springblade.modules.admin.vo.sugar.StatisticsTrendVO;
import org.springblade.modules.admin.vo.sugar.mal.ElevatorMalTopVO;
import org.springblade.modules.admin.vo.sugar.OrderDetailStatisticsVO;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Description 大屏-维保项目
 * @Author ysq
 * @Date 2022/10/12
 **/
@RestController
@RequestMapping("/admin/malfunction/screen")
@AllArgsConstructor
@Api(value = "大屏-报障维修", tags = "大屏-报障维修")
public class MalfunctionScreenController {

	private final IMaintainPlanContentService maintainPlanContentService;
	private final IMaintainPlanContentExtService maintainPlanContentExtService;
	private final IMaintainMalfunctionWorkService maintainMalfunctionWorkService;

	@PostMapping("/detail/data")
	@ApiOperation(value = "大屏-报障维修-近7天报障维修情况")
	public R<MalfunctionScreenVO> detailData(@RequestBody AnalysisStatisticalDTO param) {
		return R.data(maintainPlanContentService.detailData(param));
	}

	@PostMapping("/repair/project")
	@ApiOperation(value = "大屏-报障维修-近7天项目报障top5")
	public R<List<MalfunctionScreenVO>> repairProject(@RequestBody AnalysisStatisticalDTO param) {
		return R.data(maintainPlanContentService.repairProject(param));
	}

	@PostMapping("/repair/trend")
	@ApiOperation(value = "大屏-报障维修趋势图")
	public R<Map<String, MalfunctionScreenVO>> repairTrend(@RequestBody AnalysisStatisticalDTO param) {
		return R.data(maintainPlanContentService.repairTrend(param));
	}

	@PostMapping("/elevator/trend")
	@ApiOperation(value = "故障电梯趋势图")
	public R<Map<String, Long>> elevatorTrend(@RequestBody AnalysisStatisticalDTO param) {
		return R.data(maintainPlanContentService.elevatorTrend(param));
	}

	@PostMapping("/overview")
	@ApiOperation(value = "维修工单概况")
	public R<MalPlanOverviewVO> overview(@RequestBody AnalysisStatisticalDTO param) {
		return R.data(maintainPlanContentService.overview(param));
	}

	@PostMapping("/order/detail/statistics")
	@ApiOperation(value = "工单执行情况")
	public R<OrderDetailStatisticsVO> orderDetailStatistics(@RequestBody AnalysisStatisticalDTO param) {
		return R.data(maintainPlanContentService.orderDetailStatistics(param));
	}

	@GetMapping("/problem/item/statistics")
	@ApiOperation(value = "故障现象")
	public R<List<ChartVO>> problemItemStatistics(AnalysisStatisticalDTO param) {
		return R.data(maintainPlanContentService.problemItemStatistics(param));
	}

	@TenantIgnore
	@GetMapping("/assignment/counts/script")
	@ApiOperation("补数据：维修分配人次数脚本")
	public R<Boolean> assignmentCountsScript(){
		return R.data(maintainPlanContentExtService.assignmentCountsScript());
	}

	/**
	 * @Author lsay
	 * @Description {
	 *   电梯报障top10
	 * }
	 * @Date 14:52 2023/10/20
	 * @Param
	 * @return
	 **/
	@PostMapping("/elevator/top/ten")
	public R<List<ElevatorMalTopVO>> selectElevatorMalTopTen(@RequestBody SugarMalSearchDTO searchDTO){
		return R.data(maintainMalfunctionWorkService.selectElevatorMalTopTen(searchDTO));
	}

	/**
	 * @Author lsay
	 * @Description {
	 *   报障原因
	 * }
	 * @Date 14:52 2023/10/20
	 * @Param
	 * @return
	 **/
	@GetMapping("/problem/item/count")
	public R<List<StatisticsTrendVO>> selectMalProblemItem(SugarMalSearchDTO searchDTO){
		return R.data(maintainMalfunctionWorkService.selectMalProblemItem(searchDTO));
	}

	/**
	 * @Author lsay
	 * @Description {
	 *   耗时统计
	 * }
	 * @Date 14:52 2023/10/20
	 * @Param
	 * @return
	 **/
	@PostMapping("/plan/time")
	public R<List<StatisticsTrendVO>> selectMalPlanTime(@RequestBody SugarMalSearchDTO searchDTO){
		return R.data(maintainMalfunctionWorkService.selectMalPlanTime(searchDTO));
	}

	/**
	 * @Author lsay
	 * @Description {
	 *   工单排行榜top10
	 * }
	 * @Date 15:02 2023/10/23
	 * @Param
	 * @return
	 **/
	@PostMapping("/building/elevator/dept/user")
	public R<List<ElevatorMalTopVO>> selectMalPlanTop(@RequestBody SugarMalSearchDTO searchDTO){
		return R.data(maintainMalfunctionWorkService.selectMalPlanTop(searchDTO));
	}

	@TenantIgnore
	@GetMapping("/init/mal")
	public R<?> initMal(){
		return R.data(maintainMalfunctionWorkService.initMal());
	}

	/**
	 * 修正工单 超时数据错误问题
	 * @return 占位符
	 */
	@TenantIgnore
	@GetMapping("/init/fix")
	public R<?> initFix(){
		return R.data(maintainMalfunctionWorkService.initFix());
	}

}
